package com.zd.lib.http.okhttp;


import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Response;

/**
 * 用于上传文件的进度显示
 */
public class ProgressResponseInterceptor implements Interceptor {
    ProgressListener progressListener ;

    public ProgressResponseInterceptor(ProgressListener progressListener) {
        this.progressListener = progressListener;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Response proceed = chain.proceed(chain.request());
        return  transformer(proceed);
    }
    private  Response transformer(Response response) {
        return response.newBuilder().headers(response.headers()).body(new ProgressResponseBody(response.body(),progressListener)).build();
    }
}
